package com.qiaofang.collectmanage.stub.feign.client.impl;

import com.qiaofang.collectmanage.stub.bean.*;
import com.qiaofang.collectmanage.stub.facade.HouseAgentFacade;
import com.qiaofang.collectmanage.stub.feign.client.HouseAgentClient;
import com.qiaofang.collectmanage.stub.request.*;
import com.qiaofang.collectmanage.stub.response.*;
import com.qiaofang.common.constant.CommonResponseCode;
import com.qiaofang.common.exception.BusinessException;
import com.qiaofang.common.model.page.PageDTO;
import com.qiaofang.common.response.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author li.yi
 * @date 2018年6月29日
 */
@Service("houseAgentClient")
public class HouseAgentClientImpl implements HouseAgentClient {

    @Autowired
    private HouseAgentFacade houseAgentFacade;

    @Override
    public HouseAgentDTO getHouseAgent(GetHouseAgentDTO getHouseAgentDTO) {
        GetHouseAgentRequest request = new GetHouseAgentRequest();
        request.setGetHouseAgentDTO(getHouseAgentDTO);
        GetHouseAgentResponse response = houseAgentFacade.getHouseAgent(request);
        if (CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            return response.getData();
        } else {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }


    @Override
    public List<BatchGetHouseAgentRepeatDTO> batchGetHouseAgentRepeat(List<BatchUpdateHouseAgentDTO> batchUpdateHouseAgentDTOs) {
        BatchUpdateHouseAgentRequest request = new BatchUpdateHouseAgentRequest();
        request.setBatchUpdateHouseAgentDTOs(batchUpdateHouseAgentDTOs);
        BatchGetHouseAgentRepeatResponse response = houseAgentFacade.batchGetHouseAgentRepeat(request);
        if (CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            return response.getData();
        } else {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }

    @Override
    public void saveHouseAgent(SaveHouseAgentDTO saveHouseAgentDTO) {
        SaveHouseAgentRequest request = new SaveHouseAgentRequest();
        request.setSaveHouseAgentDTO(saveHouseAgentDTO);
        CommonResponse response = houseAgentFacade.saveHouseAgent(request);
        if (!CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }

    @Override
    public SearchHouseAgentPageDTO searchHouseAgentPage(PageDTO pageDTO, SearchHouseAgentPostDTO searchHouseAgentPostDTO) {
        SearchHouseAgentPageRequest request = new SearchHouseAgentPageRequest();
        request.setPageDTO(pageDTO);
        request.setSearchHouseAgentPostDTO(searchHouseAgentPostDTO);
        SearchHouseAgentPageResponse response = houseAgentFacade.searchHouseAgentPage(request);
        if (CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            return response.getData();
        } else {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }

    @Override
    public void batchSaveHouseAgent(List<BatchUpdateHouseAgentDTO> batchUpdateHouseAgentDTOs) {
        BatchUpdateHouseAgentRequest request = new BatchUpdateHouseAgentRequest();
        request.setBatchUpdateHouseAgentDTOs(batchUpdateHouseAgentDTOs);
        CommonResponse response = houseAgentFacade.batchSaveHouseAgent(request);
        if (!CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }


    @Override
    public void batchUpdateHouseAgent(List<BatchUpdateHouseAgentDTO> batchUpdateHouseAgentDTOs) {
        BatchUpdateHouseAgentRequest request = new BatchUpdateHouseAgentRequest();
        request.setBatchUpdateHouseAgentDTOs(batchUpdateHouseAgentDTOs);
        CommonResponse response = houseAgentFacade.batchUpdateHouseAgent(request);
        if (!CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }


    @Override
    public void removeHouseAgent(RemoveHouseAgentDTO removeHouseAgentDTO) {
        RemoveHouseAgentRequest request = new RemoveHouseAgentRequest();
        request.setRemoveHouseAgentDTO(removeHouseAgentDTO);
        CommonResponse response = houseAgentFacade.removeHouseAgent(request);
        if (!CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }
}
